package com.xesj.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

import javax.servlet.http.HttpServletRequest;

public class WebUtils {

	/**
	 * 
	* @Title: isAjax
	* @Description: 判断是否是Ajax请求
	* @param @param request
	* @param @return    设定文件
	* @return boolean    返回类型
	* @throws
	 */
	public static boolean isAjax(HttpServletRequest request){
		if (request.getHeader("x-requested-with") != null  
				&& request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest"))
		{
			return true;
		}
		return false;
	}
	
	/**
	 * 获取本机访问地址
	 * @return
	 */
	public static String getIp(HttpServletRequest request){
		/*String ip = "";
		try {
			InetAddress inet = InetAddress.getLocalHost();
			ip = inet.getHostAddress();
			//System.out.println("本机的ip=" + ip);
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}*/
		return request.getRemoteAddr();
		/*String ip = request.getHeader("x-forwarded-for");
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getHeader("WL-Proxy-Client-IP");
		}
		if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
			ip = request.getRemoteAddr();
		}
		return ip;*/
	}
	
	/**
	 * 
	* @Title: getPorjectPath
	* @Description: 获取项目路径
	* @param @return    设定文件
	* @return String    返回类型
	* @throws
	 */
	public static String getPorjectPath(){
		String nowpath = "";
		nowpath=System.getProperty("user.dir")+"/";
		
		return nowpath;
	}
}
